'use strict';
const db = uniCloud.database()

exports.main = async (event, context) => {
  const {
    id
  } = event

  if (!id) {
    return {
      code: -1,
      msg: '缺少必要参数'
    }
  }

  try {
    const collection = db.collection('food-list')
    const res = await collection.doc(id).get()

    return {
      code: 0,
      msg: 'success',
      data: res.data[0]
    }
  } catch (e) {
    return {
      code: -2,
      msg: '获取数据失败',
      error: e
    }
  }
};